package com.wd.health.view.activity.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wd.health.R;
import com.wd.health.model.bean.MessageStatusBean;
import com.wd.health.utils.RetrofitManager;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class PerfectMailActivity extends AppCompatActivity {

    private SimpleDraweeView sdv_user;
    private EditText et_email;
    private Button btn_per;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_perfect_mail);
        initView();
        initData();
    }

    private void initData() {
        SharedPreferences user = getSharedPreferences("user", Context.MODE_PRIVATE);
        String headPic = user.getString("headPic", "");
        sdv_user.setImageURI(headPic);
        btn_per.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String email = et_email.getText().toString();
                RetrofitManager.getInstance().putMailData(email, new Observer<MessageStatusBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(MessageStatusBean messageStatusBean) {
                        if (messageStatusBean.getStatus().equals("0000")){
                            Toast.makeText(PerfectMailActivity.this, "绑定邮箱成功", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(PerfectMailActivity.this, MineActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
            }
        });
    }

    private void initView() {
        sdv_user = findViewById(R.id.sdv_user);
        et_email = findViewById(R.id.et_email);
        btn_per = findViewById(R.id.btn_per);
    }
}